package com.cskaoyan.service.impl;


import com.cskaoyan.bean.vo.CatalogIndexVo;
import com.cskaoyan.bean.vo.CurrentCategoryVo;
import com.cskaoyan.bean.vo.CurrentVo;
import com.cskaoyan.mapper.WXCatalogMapper;
import com.cskaoyan.service.WXCatalogService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: ycb
 * @description: 微信小程序目录功能
 * @time: 2021/7/12 10:20
 */
@Service
public class WXCatalogServiceImpl implements WXCatalogService {

    @Autowired
    WXCatalogMapper catalogMapper;



    /**
     * @Author ycb
     * @description: 当前目录
     * @Date 10:16 2021/7/12
     * url: http://182.92.235.201:8083/wx/catalog/current?id=1036025
     */
    @Override
    public CurrentVo queryCurrentCatalog(Integer id) {

        CurrentCategoryVo categoryVo =catalogMapper.selectCurrentCatalogById(id);
        List<CurrentCategoryVo> currentCategoryVos = catalogMapper.selectCurrentCatalogByPid(categoryVo.getId());

        return new CurrentVo(categoryVo,currentCategoryVos);

    }

    /**
     * @Author ycb
     * @description:
     * @Date 11:47 2021/7/12
     * url: http://182.92.235.201:8083/wx/catalog/index
     */
    @Override
    public CatalogIndexVo queryCatalog() {
        List<CurrentCategoryVo> categoryList = catalogMapper.selectCataByLevel("L1");

        List<CurrentCategoryVo> currentSubCategory = new ArrayList<>();
        currentSubCategory = catalogMapper.selectCurrentCatalogByPid(categoryList.get(0).getId());

        return new CatalogIndexVo(categoryList,categoryList.get(0),currentSubCategory);
    }
}